package com.cosina.game.robodefence.findway;







public class Chart {
	public final int xSize, ySize;

	public Tile[][] tiles;

	public Chart(int[][] pics) {
		this.xSize = pics[0].length;
		this.ySize = pics.length;

		tiles = new Tile[ySize][xSize];
		for (int y = 0; y < ySize; y++) {
			for (int x = 0; x < xSize; x++) {
				tiles[y][x] = new Tile(x, y, pics[y][x], this);
			}
		}
	}
	
	public BlankRoute connectvie(int startX, int startY, int endX, int endY) {
		Tile start = tiles[startY][startX];
		Tile end = tiles[endY][endX];
		BlankRoute route = new BlankRoute(xSize, ySize,start,end);
		boolean result = start.isLink(route);
		if(result){
			return route;
		}else{
			return null;
		}
	}

	public Tile get(int x, int y) {
		if (null == tiles)
			throw new IllegalStateException("game is not start!");

		try {
			return tiles[y][x];
		} catch (ArrayIndexOutOfBoundsException ex) {
			return Tile.UN_EXIST_TILE;
		}
	}
}
